/**
 * 
 */
package com.wzl.qs;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

/**
 * @author g0800981
 * 
 */
public class BitmapUtil {
	public static Bitmap getBitmap(String filepath, int size)
			throws FileNotFoundException {
		FileInputStream fis = null;
		Bitmap scaledMBitmap = null;

		fis = new FileInputStream(new File(filepath));

		BitmapFactory.Options options = new BitmapFactory.Options();
		options.inSampleSize = 2;
		Bitmap mBitmap = BitmapFactory.decodeStream(fis, null, options);
		int h = mBitmap.getHeight();
		int w = mBitmap.getWidth();
		if ((w > h) && (w > size)) {
			double ratio = (double) size / w;
			w = size;
			h = (int) (ratio * h);
		} else if ((h > w) && (h > size)) {
			double ratio = (double) size / h;
			h = size;
			w = (int) (ratio * w);
		}
		scaledMBitmap = Bitmap.createScaledBitmap(mBitmap, w, h, true);
		mBitmap.recycle();

		return scaledMBitmap;
	}
}
